package com.ah.http.httpsclient.demo;

import com.ah.http.httpsclient.MyHttpsClient;
import com.ah.http.httpsclient.constants.HttpHeaderContentTypeEnum;
import com.alibaba.fastjson.JSON;
import java.util.HashMap;
import java.util.Map;

import static com.ah.shanxi_demo.sync.convert.ConvertSyncRequest.convert_sync_request_header;

/**
 * @author Tao on 2020/8/10
 */
public class ApiTestController {

    public static final String URL="https://10.254.6.151:443/api/v1";

    public static final String CENTER_KEY="7f3e379aadb04b98a3a7296a4f04eb24";

    public static void test_register() {
        //注册接口联调地址
        String url = URL+"/nodes/register";

        //实体参数
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("parent_center_code", "01");//上级节点编码
        paramsMap.put("center_code", "61");//中心节点编码
        paramsMap.put("center_name", "111");//中心节点名称
        paramsMap.put("ip", "20.61.0.102");//ip地址
        paramsMap.put("geoloc", "108.94,34.35");//经度,纬度

        //打印参数
        System.out.println("test_register【paramsMap】:"+ JSON.toJSONString(paramsMap));


        //请求头
        Map<String, String> headerMap = convert_sync_request_header(paramsMap);
        System.out.println("test_register【headerMap】："+ JSON.toJSONString(headerMap));

        //调用自己编写的sdk封装方法
//            ResponseEntity responseEntity = https_post_rest_template(url, paramsMap, headerMap);
//            System.out.println("test_register【responseEntity】："+JSON.toJSONString(responseEntity));


        try {
            Object postHttps = MyHttpsClient.sendPostHttps(url, paramsMap, headerMap, HttpHeaderContentTypeEnum.JSON.getKey());
            System.out.println("test_register【responseEntity】："+ JSON.toJSONString(postHttps));

//            {"msg":"成功","center_key":"7f3e379aadb04b98a3a7296a4f04eb24","code":200}
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public static void test_sync() {

        //同步接口接口联调地址
        String url = URL+"/node/stateSync";

        //实体参数
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("center_code", "61");//省级节点编码
        paramsMap.put("center_key", CENTER_KEY);//节点唯一标识

        //打印参数
        System.out.println("test_sync【paramsMap】:"+ JSON.toJSONString(paramsMap));

        //请求头
        Map<String, String> headerMap = convert_sync_request_header(paramsMap);
        System.out.println("test_sync【headerMap】："+ JSON.toJSONString(headerMap));

        try {
            Object postHttps = MyHttpsClient.sendPostHttps(url, paramsMap, headerMap, HttpHeaderContentTypeEnum.JSON.getKey());
            System.out.println("test_sync【postHttps】："+ JSON.toJSONString(postHttps));
//            {"msg":"成功","workorder_state":"82d736e86d7f4a66ba1d6cc006d7d370","code":200,"policy_state":"82d736e86d7f4a66ba1d6cc006d7d370"}
        } catch (Exception e) {
            e.printStackTrace();
        }
        //调用自己编写的sdk封装方法
//        ResponseEntity responseEntity = https_post_rest_template(url, paramsMap, headerMap);
//        System.out.println("test_sync【responseEntity】："+JSON.toJSONString(responseEntity));
    }


    public static void test_policy() {

        //同步接口接口联调地址
        String url = URL+"/audits/policy";

        //实体参数
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("center_code", "61");//省级节点编码
        paramsMap.put("center_key", CENTER_KEY);//节点唯一标识

        //打印参数
        System.out.println("test_policy【paramsMap】:"+ JSON.toJSONString(paramsMap));

        //请求头
        Map<String, String> headerMap = convert_sync_request_header(paramsMap);
        System.out.println("test_policy【headerMap】："+ JSON.toJSONString(headerMap));

        try {
            Object postHttps = MyHttpsClient.sendPostHttps(url, paramsMap, headerMap, HttpHeaderContentTypeEnum.JSON.getKey());
            System.out.println("test_sync【postHttps】："+ JSON.toJSONString(postHttps));

//            {"msg":"成功","code":200,"data":{"guid_type":1,"policy_code":"61-20200903-0001","guid":"1102000000001","policy_list":[{"log_type":"alarm","policy_type":"ALM-01-1","end_time":"2020-09-03 16:48:21","begin_time":"2020-09-03 16:48:21"}]}}

        } catch (Exception e) {
            e.printStackTrace();
        }

        //调用自己编写的sdk封装方法
//        ResponseEntity responseEntity = https_post_rest_template(url, paramsMap, headerMap);
//        System.out.println("test_policy【responseEntity】："+JSON.toJSONString(responseEntity));
    }

    public static void test_order() {

        //同步接口接口联调地址
        String url = URL+"/workorders/get";

        //实体参数
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("center_code", "61");//省级节点编码
        paramsMap.put("center_key", CENTER_KEY);//节点唯一标识

        //打印参数
        System.out.println("test_order【paramsMap】:"+ JSON.toJSONString(paramsMap));

        //请求头
        Map<String, String> headerMap = convert_sync_request_header(paramsMap);
        System.out.println("test_order【headerMap】："+ JSON.toJSONString(headerMap));
        try {
            Object postHttps = MyHttpsClient.sendPostHttps(url, paramsMap, headerMap, HttpHeaderContentTypeEnum.JSON.getKey());
            System.out.println("test_sync【postHttps】："+ JSON.toJSONString(postHttps));
//            {"msg":"成功","work_list":[{"work_code":"61-20200903-0001","level":2,"accdept":"it技术部","scan_type":1,"accuser":"超级管理员","title":"标题","type":1,"write_user":"admin","content":"内容"},{"work_code":"61-20200903-0001","level":2,"accdept":"it技术部","scan_type":1,"accuser":"超级管理员","title":"标题","type":1,"write_user":"admin","content":"内容"}],"code":200}
        } catch (Exception e) {
            e.printStackTrace();
        }
        //调用自己编写的sdk封装方法
//        ResponseEntity responseEntity = https_post_rest_template(url, paramsMap, headerMap);
//        System.out.println("test_order【responseEntity】："+JSON.toJSONString(responseEntity));
    }

    public static void test_data_report() {
        LogList logList=new LogList();


        //同步接口接口联调地址
        String url = URL+"/audits/dataReport";

        //实体参数
        Map<String, Object> paramsMap = new HashMap<>();
        logList.setLog_id("11-ALM-01-1-20200901-1");
        logList.setDevice_guid("1032");
        logList.setSyslog("<128>September 01 14:56:26 2020 dbapp APT~2~1~2020-09-01 14:55:34~10.61.5.73:65004~10.97.84.183:80~弱口令~HTTP~admin~中~2009011455340000060~~POST /login.php~~10.97.84.183~200~1~1~00:90:0b:48:ec:5c~c8:a7:76:75:13:00~0~Host: 10.97.84.183<br/>User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0<br/>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<br/>Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2<br/>Accept-Encoding: gzip, deflate<br/>Referer: http://10.97.84.183/<br/>Content-Type: application/x-www-form-urlencoded<br/>Content-Length: 33<br/>Connection: keep-alive<br/>Upgrade-Insecure-Requests: 1<br/>~username=admin&pwd=admin&hidden=1~~~尝试~22~1~0~5006");
        logList.setLog_type("alarm");
        logList.setPolicy_type("ALM-01-1");

        paramsMap.put("center_code", "61");//省级节点编码
        paramsMap.put("center_key", CENTER_KEY);//节点唯一标识
        paramsMap.put("policy_code", "61-20200901-0001");//节点唯一标识
        paramsMap.put("last_result_flag", "0");//节点唯一标识
        paramsMap.put("log_list", logList);//最后一条结果标识


        //打印参数
        System.out.println("test_order【paramsMap】:"+ JSON.toJSONString(paramsMap));

        //请求头
        Map<String, String> headerMap = convert_sync_request_header(paramsMap);
        System.out.println("test_order【headerMap】："+ JSON.toJSONString(headerMap));

        try {
            Object postHttps = MyHttpsClient.sendPostHttps(url, paramsMap, headerMap, HttpHeaderContentTypeEnum.JSON.getKey());
            System.out.println("test_order【postHttps】："+ JSON.toJSONString(postHttps));

        } catch (Exception e) {
            e.printStackTrace();
        }
        //调用自己编写的sdk封装方法
//        ResponseEntity responseEntity = https_post_rest_template(url, paramsMap, headerMap);
//        System.out.println("test_order【responseEntity】："+JSON.toJSONString(responseEntity));
    }

    public static void test_order_receipt() {

        //同步接口接口联调地址
        String url = URL+"/workorders/receipt";

        //实体参数
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("center_code", "61");//省级节点编码
        paramsMap.put("center_key", CENTER_KEY);//节点唯一标识
        paramsMap.put("accdept", "省中心安全运维小组");//受理部门
        paramsMap.put("accuser", "王小弟");//受理人
        paramsMap.put("phone", "13312341234");//受理人联系方式
        paramsMap.put("write_user", "王小弟");//创建人
        paramsMap.put("content", "受理结果");//回执内容
        paramsMap.put("attach_flag", "0");//附件标识
        paramsMap.put("work_code", "01-20200901-01");//工单唯一标识 省级节点编码-YYYYMMdd-自 增数，应与工单编号一致

        //打印参数
        System.out.println("test_order【paramsMap】:"+ JSON.toJSONString(paramsMap));

        //请求头
        Map<String, String> headerMap = convert_sync_request_header(paramsMap);
        System.out.println("test_order【headerMap】："+ JSON.toJSONString(headerMap));

        try {
            Object postHttps = MyHttpsClient.sendPostHttps(url, paramsMap, headerMap, HttpHeaderContentTypeEnum.JSON.getKey());
            System.out.println("test_order【postHttps】："+ JSON.toJSONString(postHttps));

        } catch (Exception e) {
            e.printStackTrace();
        }

        //调用自己编写的sdk封装方法
//        ResponseEntity responseEntity = https_post_rest_template(url, paramsMap, headerMap);
//        System.out.println("test_order【responseEntity】："+JSON.toJSONString(responseEntity));
    }

    public static void main(String[] args) {

        //测试注册接口
//        test_register();

        //测试同步接口
//        test_sync();

        //策略生成接口
//        test_policy();

        //数据采集接口 fail
//        test_data_report();

        //工单生成接口
//        test_order();

        //工单回执接口
        test_order_receipt();


    }

}
